package com.yimils.core.goods.controller;

import com.yimils.core.common.dto.RspBase;
import com.yimils.core.goods.dto.EnvironmentAddReq;
import com.yimils.core.goods.dto.EnvironmentUpdateReq;
import com.yimils.core.goods.serivce.EnvironmentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Validated
public class EnvironmentController {
    @Resource(name = "environmentService")
    EnvironmentService environmentService;

    @PostMapping("/environment/save")
    public RspBase saveEnvironment(@RequestBody EnvironmentAddReq environmentAddReq) {
        if (environmentService.saveEnvironment(environmentAddReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @PutMapping("/environment/update")
    public RspBase updateEnvironment(@RequestBody EnvironmentUpdateReq environmentUpdateReq) {
        if (environmentService.updateEnvironment(environmentUpdateReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @DeleteMapping("/environment/delete")
    public RspBase deleteEnvironment(List<Long> environmentIds) {
        if (environmentService.deleteEnvironment(environmentIds)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @GetMapping("/environment/list")
    public RspBase listEnvironment() {
        RspBase rsp = RspBase.OK();
        rsp.put("data", environmentService.listEnvironment());
        return rsp;
    }

}
